package com.srolorz.fmtp.thread.pool.executor.event;

import com.srolorz.fmtp.thread.pool.executor.exception.ThreadExecuteException;

/**
 * @author eleven
 */
public abstract class ThreadPoolEvent<T> {
    private String threadGroupName;
    private T entity;
    private boolean doing = false;

    public ThreadPoolEvent(T entity) {
        if (null != entity) {
            this.entity = entity;
        }
    }

    public abstract void executeEvent();

    public abstract Object executeCallEvent();

    public T getEntity() {
        return entity;
    }

    public <E extends ThreadPoolEvent<T>> E setT(T entity) {
        this.entity = entity;
        return (E) this;
    }

    public String getThreadGroupName() {
        return threadGroupName;
    }

    public <E extends ThreadPoolEvent<T>> E setThreadGroupName(String threadGroupName) {
        this.threadGroupName = threadGroupName;
        return (E) this;
    }

    public void doing() {
        if (doing) {
            throw new ThreadExecuteException(Thread.currentThread().getName() + "thread is running!!");
        } else {
            doing = true;
        }
    }
}
